package com.zrt.pad.commonui.task;

import android.util.Log;

import com.zrt.pad.datasource.DataSourceHelper;
import com.zrt.pad.datasource.DataSourceInstance;
import com.zrt.pad.datasource.OptionName;

public class SyncDaemonThread extends Thread {

	public SyncDaemonThread() {
		super();
		setDaemon(true);
	}
	
	@Override
	public void run() {
		super.run();
		Log.i("SyncDaemon", "stared!");
		while(true){
			/**
			 * 
			 */
			try {
				Thread.sleep(30);
			} catch (InterruptedException e1) {
			}
			String interval = DataSourceInstance.instance.getOption(OptionName.AUTO_SYNC_TIME_INTERVAL);
			long intervalTime = 3 * 3600 * 1000;
			if (interval != null) {
				intervalTime = Long.parseLong(interval);
			}
			try {				
				DataSourceHelper.UserCheckIn();
				DownloadImageTask.task.download(null, null);
				
			} catch (Exception e) {
			} finally {
				try {
					Thread.sleep(intervalTime);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
}
